<template>
  <div>
    <van-nav-bar
      :z-index="999"
      :fixed="true"
      left-arrow
      @click-left="onClickLeft"
      :placeholder="true"
      title="评价"
    ></van-nav-bar>
    <!-- 评价 -->
    <div class="evaluate">
      <!-- 订单 -->
      <div class="evaluate-title">
        <!-- <img :src="title.img" /> -->
        <p>{{ title.cnr }}</p>
      </div>

      <div class="e-estimate">驾校评价</div>
      <div class="hierarchy">
        <div>
          <p>驾校设施评分</p>
          <van-rate v-model="sGrade" />
        </div>
        <div>
          <p>驾校质量</p>
          <van-rate v-model="Sgrade" />
        </div>

        <!-- 输入内容 -->
      </div>
      <van-field
        v-model="Smessage"
        rows="2"
        autosize
        label="评价"
        type="textarea"
        maxlength="50"
        placeholder="请输入评价"
        show-word-limit
      />

      <div class="e-estimate">教练评价</div>

      <div class="hierarchy">
        <div>
          <p>教练服务质量</p>
          <van-rate v-model="value1" />
        </div>
        <div>
          <p>教练技术</p>
          <van-rate v-model="value2" />
        </div>

        <!-- 输入内容 -->
      </div>
      <van-field
        v-model="message"
        rows="2"
        autosize
        label="评价"
        type="textarea"
        maxlength="50"
        placeholder="请输入评价"
        show-word-limit
      />
      <van-button
        class="submit-evaluate"
        round
        size="large"
        type="info"
        @click="submit"
        >提交</van-button
      >
    </div>
  </div>
</template>

<script>
import {
  orderInformation,
  referEvaluate
} from "../../../assets/js/api/user.js";
import { baseURL } from "../../../assets/js/config";
import { Dialog, Toast } from "vant";
export default {
  name: "Evaluate",
  data() {
    return {
      value1: 1, // 教练服务质量
      value2: 1, // 教练技术
      Smessage: "", // 评价内容
      baseURL: "",
      title: "",
      sGrade: 1, // 设施评分
      Sgrade: 1, // 驾校质量评分
      message: "" // 驾校评价内容
    };
  },

  created() {
    this.baseURL = baseURL;
    orderInformation(this.$route.params.id).then(res => {
      this.title = res.data[0];
      console.log(res.data);
    });
    let dsBridge = require("dsbridge");
    dsBridge.call("goBack", "", function() {
      history.go(-1);
    });
  },
  methods: {
    submit() {
      if (this.Smessage == "" || this.message == "") {
        Toast("请输入评价内容");
        return;
      }
      let obj = {
        sspf: this.sGrade,
        ffzl: this.Sgrade,
        jxremarks: this.Smessage,
        fwzl: this.value1,
        jljs: this.value2,
        remarks: this.message,
        orderId: this.$route.params.id
      };
      referEvaluate(obj).then(res => {
        if (res.code == 0) {
          Dialog.alert({
            message: "评价成功"
          }).then(() => {
            // on close
            this.$router.go(-1);
          });
        }
      });
    },

    onClickLeft() {
      this.$router.go(-1);
    }
  },
  components: {
    [Dialog.Component.name]: Dialog.Component
  }
};
</script>

<style></style>
